import {
  getCertificateApplyInformation,
  getCertificateOrderId
} from "../../../api/certificate";
import {
  pay
} from "../../../api/user";

// pages/credentials/info/info.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0, // 申请ID
    type: 0, //0显示信息 1进行支付
    sexOptions: ['未知', '男', '女'],
    info: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: Number(options.id),
      type: Number(options.type),
    })

    this.loadInformation();
  },

  /**
   * 加载信息
   */
  loadInformation() {
    getCertificateApplyInformation(this.data.id).then(res => {
      this.setData({
        info: res
      })
    })
  },

  /**
   * 支付
   */
  async onPay() {
    let res = await getCertificateOrderId(this.data.id);

    await pay(res.orderId);

    wx.showToast({
      title: '支付成功',
      icon: 'success',
      mask: true,
    })
    let timer = setTimeout(() => {
      clearTimeout(timer);
      wx.navigateBack({});
    }, 2000);
  },

})